package com.example.administrator.threelibrary.dagger;


import com.example.administrator.commonlibrary.bese.BaseAppliction;
import com.example.administrator.threelibrary.dagger.component.DaggerPresenterComponent;
import com.example.administrator.threelibrary.dagger.component.PresenterComponent;
import com.example.administrator.threelibrary.dagger.module.PresenterMoudule;
import com.example.administrator.threelibrary.presenter.activity.MaiActivityPresenter;
import com.example.administrator.threelibrary.presenter.fragment.ThreeFragmentPresenter;

/**
 * 作者：wang_hong_wei
 * 创建时间：2018/9/18
 * 描述：p层实例化对象的帮助类
 */
public class NewPresenterInject implements PresenterComponent{

    private PresenterComponent build;

    public static NewPresenterInject getInject() {
        return new NewPresenterInject();
    }

    public <S, T> void inject(S module, T context) {
        if (module == null) module = (S) new PresenterMoudule();
        build = DaggerPresenterComponent.builder().presenterMoudule((PresenterMoudule) module).overallSituationComponent(BaseAppliction.getOverallSituation()).build();

        if (context instanceof MaiActivityPresenter)inject((MaiActivityPresenter) context);
        if (context instanceof ThreeFragmentPresenter)inject((ThreeFragmentPresenter) context);
    }

    @Override
    public void inject(MaiActivityPresenter presenter) {
        build.inject(presenter);
    }

    @Override
    public void inject(ThreeFragmentPresenter presenter) {
        build.inject(presenter);
    }
}
